﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using LeadTeam.Exam.Entities;
using LeadTeam.Exam.Interafce;
using LeadTeam.Exam.DbContext;

namespace LeadTeam.Exam.DataSevice
{
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
   
    public partial class DataService
    {

        private IOrganizations iOrg;
        private IExams iExam;
        public DataService()
        {
            iOrg = new OrganizationsManipulate();
            iExam = new ExamManipulate();
        }

        [WebGet(UriTemplate = "Exam", ResponseFormat = WebMessageFormat.Json)]
        public List<Exams> GetCollection_Exam()
        {
            return iExam.GetList();
        }

        [WebGet(UriTemplate = "Organization", ResponseFormat = WebMessageFormat.Json)]
        public List<Organizations> GetCollection_Organization()
        {
            return iOrg.GetList();
        }

        [OperationContract]
        [WebInvoke(UriTemplate = "Organization/AddChild", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public void Create_Organization_Child(Organizations postEntity)
        {
             iOrg.CreateEntity_Child(postEntity);
        }

        [OperationContract]
        [WebInvoke(UriTemplate = "Organization/AddParent/{id}", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public void Create_Organization(Organizations postEntity,string id)
        {
            iOrg.CreateEntity_Parent(postEntity,id);
        }

        [OperationContract]
        [WebInvoke(UriTemplate = "Organization/{id}", Method = "DELETE")]
        public void Delete_Client(string id)
        {
            iOrg.DeleteEntity(id);
        }

        [OperationContract]
        [WebInvoke(UriTemplate = "Organization/UpdateAsParent/{id}/{parentId}", Method = "PUT", RequestFormat = WebMessageFormat.Json)]
        void Update_Client_ParentId_AsParent(string id, string parentId)
        {
            iOrg.UpdateAsParent(id, parentId);
            //iOrg.Update(id, postEntity);
        }

        [OperationContract]
        [WebInvoke(UriTemplate = "Organization/UpdateAsChild/{id}/{parentId}", Method = "PUT", RequestFormat = WebMessageFormat.Json)]
        void Update_Client_ParentId_AsChild(string id, string parentId)
        {
            iOrg.UpdateAsChild(id,parentId);
            //iOrg.Update(id, postEntity);
        }

        [OperationContract]
        [WebInvoke(UriTemplate = "Organization/{id}", Method = "PUT", RequestFormat = WebMessageFormat.Json)]
        void Update_Client(string id, Organizations postEntity)
        {
            iOrg.Update(id, postEntity);
        }
      


        //[WebGet(UriTemplate = "")]
        //public List<SampleItem> GetCollection()
        //{
        //    // TODO: Replace the current implementation to return a collection of SampleItem instances
        //    return new List<SampleItem>() { new SampleItem() { Id = 1, StringValue = "Hello" } };
        //}

        //[WebInvoke(UriTemplate = "", Method = "POST")]
        //public SampleItem Create(SampleItem instance)
        //{
        //    // TODO: Add the new instance of SampleItem to the collection
        //    throw new NotImplementedException();
        //}

        //[WebGet(UriTemplate = "{id}")]
        //public SampleItem Get(string id)
        //{
        //    // TODO: Return the instance of SampleItem with the given id
        //    throw new NotImplementedException();
        //}

        //[WebInvoke(UriTemplate = "{id}", Method = "PUT")]
        //public SampleItem Update(string id, SampleItem instance)
        //{
        //    // TODO: Update the given instance of SampleItem in the collection
        //    throw new NotImplementedException();
        //}

        //[WebInvoke(UriTemplate = "{id}", Method = "DELETE")]
        //public void Delete(string id)
        //{
        //    // TODO: Remove the instance of SampleItem with the given id from the collection
        //    throw new NotImplementedException();
        //}



    }
}
